package network

import (
	"github.com/gin-gonic/gin"
	"net/http"
)

type ResponseParam struct {
	code int    `json:"code"` // 状态码
	msg  string `json:"msg"`  // 描述
	data gin.H  `json:"data"` // 接口信息
}

func Response(ctx *gin.Context, httpStatus int, code int, data gin.H, msg string) {
	ctx.JSON(httpStatus, gin.H{
		"code": code,
		"msg":  msg,
		"data": data,
	})
}

func Success(ctx *gin.Context, msg string, data gin.H) {
	Response(ctx, http.StatusOK, 200, data, msg)
}

func Fail(ctx *gin.Context, msg string, data gin.H) {
	Response(ctx, http.StatusOK, http.StatusUnprocessableEntity, data, msg)
}
